package com.chagee.store.operation.server.service.third;

import com.alibaba.fastjson.JSONObject;
import com.chagee.base.exception.SoaException;
import com.chagee.base.utils.PaginationData;
import com.chagee.base.utils.PaginationRequest;
import com.chagee.base.utils.SoaResponse;
import com.chagee.base.utils.SoaUtil;
import com.chagee.scm.api.supplier.request.*;
import com.chagee.scm.api.supplier.response.*;
import com.chagee.scm.api.supplier.service.SupplierServiceApi;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author : hk
 * @Date : 2024/10/25
 */

@Slf4j
@Service
@RequiredArgsConstructor
public class ScmThirdService {

	@Resource
	private SupplierServiceApi supplierServiceApi;

	/**
	 * 供应商列表
	 * @param request
	 * @return
	 */
	public PaginationData<SupplierSimpleResponseBO> searchPageByName(PaginationRequest<SupplierSimpleRequestBO> request) {
		try {
			log.info("ScmThirdService_SupplierServiceApi.searchPageByName,request:{}", JSONObject.toJSONString(request));
			SoaResponse<PaginationData<SupplierSimpleResponseBO>, Void> response = supplierServiceApi.searchPageByName(request);
			log.info("ScmThirdService_SupplierServiceApi.searchPageByName,response:{}", JSONObject.toJSONString(response));
			return SoaUtil.unpack(response);
		} catch (Exception e) {
			log.error("ScmThirdService_SupplierServiceApi.searchPageByName,request:{},error:{}", JSONObject.toJSONString(request), e);
			return null;
		}
	}

	/**
	 * 供应商查询
	 * @param request
	 * @return
	 */
	public List<SupplierSimpleInfoBO> querySupplierInfoByIds(QuerySupplierRequestBo request) {
		try {
			log.info("ScmThirdService_SupplierServiceApi.querySupplierInfoByIds,request:{}", JSONObject.toJSONString(request));
			SoaResponse<List<SupplierSimpleInfoBO>,SoaException> response = supplierServiceApi.querySupplierInfoByIds(request);
			log.error("ScmThirdService_SupplierServiceApi.querySupplierInfoByIds,response:{}", JSONObject.toJSONString(response));
			return SoaUtil.unpack(response);
		} catch (Exception e) {
			log.error("ScmThirdService_SupplierServiceApi.querySupplierInfoByIds,request:{},error:{}", JSONObject.toJSONString(request), e);
			return new ArrayList<>();
		}
	}

	/**
	 * 供应商列表_服务类-清洁消杀类
	 * @param request
	 * @return
	 */
	public PaginationData<SupplierBaseBO> searchSupplier(PaginationRequest<SearchSupplierBaseBO> request) {
		try {
			log.info("ScmThirdService_SupplierServiceApi.searchSupplier,request:{}", JSONObject.toJSONString(request));
			SoaResponse<PaginationData<SupplierBaseBO>,String> response = supplierServiceApi.searchSupplier(request);
			log.info("ScmThirdService_SupplierServiceApi.searchSupplier,response:{}", JSONObject.toJSONString(response));
			return SoaUtil.unpack(response);
		} catch (Exception e) {
			log.error("ScmThirdService_SupplierServiceApi.searchSupplier,request:{},error:{}", JSONObject.toJSONString(request), e);
			return null;
		}
	}
}
